/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tutorial.BuilderSiDAO;

import tutorial.BuilderSiDAO.BuilderPattern.StdExporter;
import tutorial.BuilderSiDAO.BuilderPattern.SwingImporter;
import tutorial.BuilderSiDAO.DAOPattern.StdPersoanaDAO;
import tutorial.BuilderSiDAO.DAOPattern.SwingPersoanaDAO;
import tutorial.BuilderSiDAO.commons.ptBuilderPersoana;
import tutorial.BuilderSiDAO.commons.ptBuilderPersoana.Exporter;
import tutorial.BuilderSiDAO.commons.ptBuilderPersoana.Importer;
import tutorial.BuilderSiDAO.commons.ptDAOPersoana;
import tutorial.BuilderSiDAO.commons.ptDAOPersoana.PersoanaDAO;

/**
 * Aici am vrut sa arat cum cele doua implentari (Std si Swing) se pot combina 
 * fara probleme din cauza ca implementarile(ptBuilderPersoana si ptDAOPersoana) 
 * ale clase Persoana nu stiu nici un detaliu de implementare al interfelelor
 * Importer/Exporter si PersoanaDAO
 *  
 * ele folosec ce li se ofera (si nu pun intrebari :P)
 * @author Boogie
 */
public class TutorialCombinat extends javax.swing.JFrame {

    public TutorialCombinat() {
        initComponents();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        persoanaGUIInput = new tutorial.BuilderSiDAO.customGUI.PersoanaGUIInput();
        printezaInConsola = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        persoanaGUIOutput = new tutorial.BuilderSiDAO.customGUI.PersoanaGUIOutput();
        iaDateDinConsola = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Cu Builder"));

        printezaInConsola.setText("Printeza in Consola");
        printezaInConsola.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                printezaInConsolaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(persoanaGUIInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(printezaInConsola, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addComponent(persoanaGUIInput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(printezaInConsola))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Cu DAO"));

        iaDateDinConsola.setText("Ia date din Consola");
        iaDateDinConsola.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                iaDateDinConsolaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(persoanaGUIOutput, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(iaDateDinConsola, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(persoanaGUIOutput, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(iaDateDinConsola))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    private void printezaInConsolaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_printezaInConsolaActionPerformed
        Importer importer = new SwingImporter(this.persoanaGUIInput);
        ptBuilderPersoana p = new ptBuilderPersoana(importer);
        Exporter exporter = new StdExporter();
        p.export(exporter);
    }//GEN-LAST:event_printezaInConsolaActionPerformed

    private void iaDateDinConsolaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_iaDateDinConsolaActionPerformed
        PersoanaDAO pDaoInput = new StdPersoanaDAO();
        //Din cauza ca nu luam date din GUI primu param poate sa fie null
        PersoanaDAO pDaoOutput = new SwingPersoanaDAO(null, this.persoanaGUIOutput);        
        
        ptDAOPersoana p = pDaoInput.importPersoasa();   
        pDaoOutput.exportPersoana(p);
    }//GEN-LAST:event_iaDateDinConsolaActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TutorialCombinat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TutorialCombinat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TutorialCombinat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TutorialCombinat.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new TutorialCombinat().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton iaDateDinConsola;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private tutorial.BuilderSiDAO.customGUI.PersoanaGUIInput persoanaGUIInput;
    private tutorial.BuilderSiDAO.customGUI.PersoanaGUIOutput persoanaGUIOutput;
    private javax.swing.JButton printezaInConsola;
    // End of variables declaration//GEN-END:variables
}
